package com.eightworld3.supermarket.controller;

import com.eightworld3.supermarket.domain.UserInfo;
import com.eightworld3.supermarket.service.UserInfoService;
import com.eightworld3.supermarket.service.dto.UserInfoDTO;
import com.eightworld3.supermarket.service.dto.add.UserInfoAddDTO;
import com.eightworld3.supermarket.service.dto.result.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author EightWorld3
 */
@Tag(name = "UserInfoController",description = "用户管理")
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
    private final UserInfoService userInfoService;

    /**
     * UserInfoController构造方法
     * @param userInfoService 用户Service
     */
    public UserInfoController(UserInfoService userInfoService){
        this.userInfoService = userInfoService;
    }

    /**
     * 查询全部
     * @return 返回所有UserInfo(用户)
     */
    @Operation(summary = "查询全部用户(UserInfo)",description = "查询全部用户(UserInfo)")
    @GetMapping("/allUserInfo")
    public List<UserInfo> getAll(){
        return userInfoService.selectAll();
    }

    /**
     * 根据userId查询UserInfo
     * @param userId ID号
     * @return 返回userId对应的UserInfo对象(经ResponseResult包装类修饰)
     */
    @Operation(summary = "根据userId查询用户(UserInfo)",description = "根据userId查询用户(UserInfo)")
    @GetMapping("/getUserInfoByUserId/{userId}")
    public ResponseResult getUserInfoByUserId(@PathVariable("userId") int userId){
       return userInfoService.selectByUserId(userId);
    }

    /**
     * 新增UserInfo
     * @param userInfoAddDTO UserInfo新增DTO对象
     * @return 返回当前当次新增状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "新增用户(UserInfo)",description = "Test：用户名(varchar(32))、密码(varchar(32)、至少6位)、用户权限(默认为0)、联系方式(varchar(14)、备注(varchar(120))")
    @PostMapping("/addUserInfo")
    public ResponseResult addUserInfo(@RequestBody UserInfoAddDTO userInfoAddDTO){
        return userInfoService.addUserInfo(userInfoAddDTO);
    }

    /**
     * 更新UserInfo
     * @param userInfoDTO UserInfo DTO对象
     * @return 返回当前当次更新状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "更新用户(UserInfo)",description = "Test：用户名(varchar(32))、密码(varchar(32)、至少6位)、用户权限(默认为0)、联系方式(varchar(14)、备注(varchar(120))")
    @PutMapping("/updateUserInfo")
    public ResponseResult updateUserInfo(@RequestBody UserInfoDTO userInfoDTO){
        return userInfoService.updateUserInfo(userInfoDTO);
    }

    /**
     * 根据userId删除UserInfo
     * @param userId ID号
     * @return 返回当前当次删除状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "根据userId删除用户(UserInfo)",description = "根据userId删除用户(UserInfo)")
    @DeleteMapping("/deleteUserInfoByUserId/{userId}")
    public ResponseResult deleteUserInfoByUserId(@PathVariable("userId")int userId){
        return userInfoService.deleteUserInfoById(userId);
    }

}
